<?php

/**
 * This is the model class for table "zy_potential_customers_list".
 *
 * The followings are the available columns in table 'zy_potential_customers_list':
 * @property integer $potential_customers_list_id
 * @property string $potential_customers_list_name
 *
 * The followings are the available model relations:
 * @property ZyPotentialCustomers[] $zyPotentialCustomers
 */
class PotentialCustomersList extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PotentialCustomersList the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_potential_customers_list';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('potential_customers_list_name', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('potential_customers_list_id, potential_customers_list_name', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'zyPotentialCustomers' => array(self::HAS_MANY, 'ZyPotentialCustomers', 'potential_customers_list_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'potential_customers_list_id' => Yii::t('base','Potential Customers List'),
			'potential_customers_list_name' => Yii::t('base','Potential Customers List Name'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('potential_customers_list_id',$this->potential_customers_list_id);
		$criteria->compare('potential_customers_list_name',$this->potential_customers_list_name,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	//通过客户名单列表id得到名字
	public function getListName($id)
	{
	$potentialcustomerslist=PotentialCustomersList::model()->findByPk($id);
	return $potentialcustomerslist->potential_customers_list_name;
	}
	
	//通过客户id找到客户列表的名字
	public function getPotentialCustomerListName($id)
	{
	$potentialcustomer=PotentialCustomers::model()->findByPk($id);
	$potentialcustomerlist=PotentialCustomersList::model()->findByPk($potentialcustomer->potential_customers_list_id);
	return $potentialcustomerlist->potential_customers_list_name;
	}
}